/**
 * 修改ant mobile 样式的方法
@example
 import listItemStyles from 'antd-mobile/lib/list/style/index';
 const newStyle = {};
 let myStyle = [
 {
        cssType: 'Item', // 要改的样式的类名字
        val: [
            { key: 'paddingLeft', value: 0},
        ]
    },
 {
        cssType: 'Line', // 要改的样式的类名字
        val: [
            { key: 'paddingRight', value: 0},
        ]
    },
 ]
 changeStyle(newStyle, listItemStyles, myStyle)
 */
export const changeStyle = (newObj, style, data) => {
  for (const key in style) {
    if (Object.prototype.hasOwnProperty.call(style, key)) {
      newObj[key] = {...StyleSheet.flatten(style[key])};
      if (data.length > 0) {
        data.map((item, index) => {
          if (key === item.cssType) {
            item.val.map((items, indexs) => {
              newObj[key][items.key] = items.value;
            })
          }
        })
      }
    }
  }
};

/**
 *拦截不必要的渲染
 * @example
 shouldComponentUpdate(nextProps, nextState) {
    return (
      shouldUpdate(this.state, nextState, ['activeNum',]) ||
      shouldUpdate(this.props, nextProps, ['activeNum', 'tabbarData']))
  }
 */
export const shouldUpdate=(a, b, paths)=> {
  for (let i = 0; i < paths.length; i++) {
    const equals = isEqual(get(a, paths[i]), get(b, paths[i]));
    if (!equals) {
      return true;
    }
  }
  return false;
};